package es.upv.tricia.rest;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public abstract class GsonHttpResponseHandler<T> extends
		AsyncHttpResponseHandler
{
	private Class<T> clazz;

	public GsonHttpResponseHandler(Class<T> clazz)
	{
		this.clazz = clazz;
	}

	@Override
	public void onSuccess(String response)
	{
		try {
			Gson gson = new GsonBuilder().create();
			JSONObject json = new JSONObject(response);
			onSuccess(gson.fromJson(json.toString(), clazz));
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public void onSuccess(T response)
	{
	}

}
